package gold.digger;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by fanzhenyu02 on 2020/6/27.
 * common problem solver template.
 */
public class LC313 {
    public long startExecuteTime = System.currentTimeMillis();


    class Solution {
        public int nthSuperUglyNumber(int n, int[] primes) {

            int[] dp = new int[n];
            dp[0] = 1;

            int k = primes.length;
            int[] index = new int[k];

            for (int i = 1; i < n; i++) {
                int min = Integer.MAX_VALUE;
                for (int j = 0; j < k; j++) {
                    if (min > dp[index[j]] * primes[j]) {
                        min = dp[index[j]] * primes[j];
                    }
                    dp[i] = min;
                }
                for (int j = 0; j < k; j++) {
                    if (min == dp[index[j]] * primes[j]) {
                        index[j]++;
                    }
                }
            }
            return dp[n - 1];
        }
    }

    public void run() {
        Solution solution = new Solution();
        List<Integer> list = new ArrayList<>();
        System.out.println(solution.toString());
    }

    public static void main(String[] args) throws Exception {
        LC313 an = new LC313();
        an.run();

        System.out.println("\ncurrent solution total execute time: " + (System.currentTimeMillis() - an.startExecuteTime) + " ms.");
    }
}
